<?php

namespace App\Http\Controllers\Api\Feedback;

use App\Http\Controllers\Controller;
use App\Models\Activity;
use App\Models\Banner;
use App\Models\Feedback;
use App\Models\Notice;
use App\Models\Posts;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class FeedbackController extends Controller
{
    /**
     * 提交意见反馈
     *
     * @param Request $request
     * @return array
     */
    public function submit(Request $request): array
    {
        $user = auth('api')->user();
//        $table = 'feedback_submit';
//        $validator = FormVerify($table, $request);
//        if ($validator['code'] == 201) {
//            return retError($validator['msg']);
//        }
        $content = request('content');
        if(!$content){
            return retError('反馈内容不能为空');
        }
        $create = [
            'user_id'=>$user->id,
            'username'=>$user->username,
            'content'=>$content,
            'image'=>request('image'),
            'create_mobile'=>request('mobile'),
        ];
        DB::beginTransaction();
        try {
            Feedback::query()->create($create);
            DB::commit();
            return ret('提交成功!');
        } catch (\Exception $e) {
            DB::rollBack();
            return retError($e->getMessage());
        }
    }

}
